/*
 * Copyright 2008 CSC Consulting Group under the Apache License, 
 * Version 2.0 (the "License"); you may not use this file except in 
 * compliance with the License. You may obtain a copy of the License at 
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable 
 * law or agreed to in writing, software distributed under the License is 
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
 * either express or implied. See the License for the specific language 
 * governing permissions and limitations under the License.
 */
package com.waw.journal.plugin.action;

import com.jivesoftware.base.Log;
import com.waw.journal.plugin.JournalConsts;

/**
 * This action class supports the presentation of the Fitness Journal page.
 * It provides a function that indicates whether the user has indicated autologin in their profile.
 * <p>
 * The execute method checks whether the account has been set up and returns either SUCCESS if it has
 * or NO_JOURNAL_ACCOUNT if it has not.
 *
 * @author jtremlett
 */
public class ShowJournalAction extends BaseJournalAction 
{

	private static final long serialVersionUID = 1L;
	

	/**
	 * Indicates whether the user has indicated auto login is set in their profile.
	 * @return True if auto login is set, False if not.
	 */
	public boolean getAutoLogin() {
		String autoLogin = getUser().getProperties().get(JournalConsts.USER_JOURNAL_AUTOLOGIN);
		if(autoLogin == null) return false;
		Log.info("AutoLogin set to: "+ autoLogin);
		return autoLogin.toLowerCase().equals("yes");
	}
	
    /**
     * The execute method checks the setting for the username.  If it is not set, that means the 
     * account hasn't been established by the administrator.
     * The result is set accordingly.
     * 
     * @see com.jivesoftware.community.action.ViewProfile#execute()
     */
    public String execute() {
        super.execute();
        
        String username = getUser().getProperties().get(JournalConsts.USER_JOURNAL_USERNAME);
        if(username == null || username.length() == 0) return JournalConsts.NO_JOURNAL_ACCOUNT_RESULT;
        
        return SUCCESS;
    }
	

}
